package com.yunhe.control;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;

import com.yunhe.bean.Admin;
import com.yunhe.service.AdminService;
import com.yunhe.util.MySession;

/**
 * Servlet implementation class AdminList
 */
@WebServlet("/adminlist")
public class AdminList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminList() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//获取页码
		String page =request.getParameter("pages");
		int page2 =0;
		if(page==null){
			page2=0;
			int currage=0;
		}else{
			page2=Integer.parseInt(page);
		}
		
		
		//获取到从数据库中所有的数据
		
		AdminService adm =new AdminService();
		int zongtiao =adm.getCount().size();
		
		int zongye =zongtiao%3==0?zongtiao/3:zongtiao/3+1;
		
		List<Admin> list =adm.getFenye(page2*3);
		
		request.getSession().setAttribute("list", list);
		
		request.getSession().setAttribute("currage", page);
		
		request.getSession().setAttribute("zongtiaoshu", zongtiao);
		
		request.getSession().setAttribute("zongye", zongye-1);
		
		
		response.sendRedirect("hou/admin-list.jsp");
		
	}

}
